package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.configuration.OrderRestTemplate;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.entities.User;
import com.atguigu.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class PaymentController {
//    private final String PATH = "http://localhost:8002";
    private final String PATH = "http://CONSUMESERVICE";
    @Autowired
    private PaymentService paymentService;
    @Autowired
    private RestTemplate restTemplate;
    @RequestMapping("/select")
    public Payment getPaymentById(Long id){
        Payment payment = paymentService.getPaymentById(id);
        User user = restTemplate.getForObject(PATH + "/user/select?id=" + id,User.class);
        payment.setUser(user);
        return payment;
    }
    @RequestMapping("/insert")
    public Integer insert(Payment payment){
        return paymentService.insert(payment);
    }
    @RequestMapping("/insertOther")
    public int insertOther(User user){
        return restTemplate.postForObject(PATH + "/user/insert",user,Integer.class);
    }
}
